home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / umountnfs.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2008-10-14  |  2KB  |  109 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          umountnfs
  4. # Required-Start:
  5. # Required-Stop:     umountfs
  6. # Should-Stop:       $network $portmap nfs-common
  7. # Default-Start:
  8. # Default-Stop:      0 6
  9. # Short-Description: Unmount all network filesystems except the root fs.
  10. # Description:       Also unmounts all virtual filesystems (proc, devfs,
  11. #                    devpts, usbfs, sysfs) that are not mounted at the
  12. #                    top level.
  13. ### END INIT INFO
  14.  
  15. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  16. KERNEL="$(uname -s)"
  17. RELEASE="$(uname -r)"
  18. . /lib/init/vars.sh
  19.  
  20. . /lib/lsb/init-functions
  21.  
  22. case "${KERNEL}:${RELEASE}" in
  23.   Linux:[01].*|Linux:2.[01].*)
  24.     FLAGS=""
  25.     ;;
  26.   Linux:2.[23].*|Linux:2.4.?|Linux:2.4.?-*|Linux:2.4.10|Linux:2.4.10-*)
  27.     FLAGS="-f"
  28.     ;;
  29.   *)
  30.     FLAGS="-f -l"
  31.     ;;
  32. esac
  33.  
  34. do_stop () {
  35.     # Write a reboot record to /var/log/wtmp before unmounting
  36.     halt -w
  37.  
  38.     # Remove bootclean flag files (precaution against symlink attacks)
  39.     rm -f /tmp/.clean /var/lock/.clean /var/run/.clean
  40.  
  41.     #
  42.     # Make list of points to unmount in reverse order of their creation
  43.     #
  44.  
  45.     exec 9<&0 </etc/mtab
  46.  
  47.     DIRS=""
  48.     while read DEV MTPT FSTYPE OPTS REST
  49.     do
  50.         case "$MTPT" in
  51.           /|/proc|/dev|/dev/pts|/dev/shm|/proc/*|/sys|/lib/init/rw)
  52.             continue
  53.             ;;
  54.           /var/run)
  55.             if [ yes = "$RAMRUN" ] ; then
  56.                 continue
  57.             fi
  58.             ;;
  59.           /var/lock)
  60.             if [ yes = "$RAMLOCK" ] ; then
  61.                 continue
  62.             fi
  63.             ;;
  64.         esac
  65.         case "$FSTYPE" in
  66.           nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs)
  67.             DIRS="$MTPT $DIRS"
  68.             ;;
  69.           proc|procfs|linprocfs|devfs|devpts|usbfs|usbdevfs|sysfs)
  70.             DIRS="$MTPT $DIRS"
  71.             ;;
  72.         esac
  73.         case "$OPTS" in
  74.           _netdev|*,_netdev|_netdev,*|*,_netdev,*)
  75.             DIRS="$MTPT $DIRS"
  76.             ;;
  77.         esac
  78.     done
  79.  
  80.     exec 0<&9 9<&-
  81.  
  82.     if [ "$DIRS" ]
  83.     then
  84.         [ "$VERBOSE" = no ] || log_action_begin_msg "Unmounting remote and non-toplevel virtual filesystems"
  85.         umount $FLAGS $DIRS
  86.         ES=$?
  87.         [ "$VERBOSE" = no ] || log_action_end_msg $ES
  88.     fi
  89. }
  90.  
  91. case "$1" in
  92.   start)
  93.     # No-op
  94.     ;;
  95.   restart|reload|force-reload)
  96.     echo "Error: argument '$1' not supported" >&2
  97.     exit 3
  98.     ;;
  99.   stop|"")
  100.     do_stop
  101.     ;;
  102.   *)
  103.     echo "Usage: umountnfs.sh [start|stop]" >&2
  104.     exit 3
  105.     ;;
  106. esac
  107.  
  108. :
  109.